#解决登录返回”验证码错误“的问题
# 思路：因为tpshop商城的登陆操作其实是包含”发送验证码“和”登录“两个不同的接口
# 我们只需要在请求登录接口之前，先请求”发送验证码“接口，拿到验证码接口返回的cookie
# 信息之后，再次请求登录接口
# 导包
import requests
# 发送请求
#请求验证码接口(获取验证码接口返回的cookie信息)
# resp1=requests.get(url="http://localhost/index.php?m=Home&c=User&a=verify&r=0.7421460428338859"
#                    ,headers={"cookies":"Pycharm-cc9469f0=3b40690b-6729-4e15-8496-a216c385ee88; is_mobile=0; is_distribut=1; province_id=1; city_id=2; district_id=3; PHPSESSID=04hhcodmhm2pe8mou1krsqhsr1; cn=0"})
#获取验证码接口返回的cookie信息
# my_cookie=resp1.cookies
# #登录请求
# resp2=requests.post(url="http://localhost/index.php?m=Home&c=User&a=do_login&t=0.9450750218212879",
#                     headers={"content_type":"application/x-www-form-urlencoded; charset=UTF-8"},
#                     data={"username":"18888888888","password":"123456","verify_code":"8888"},
#                     cookies=my_cookie)
# # 获取响应信息
# print(resp2.json())
# sess=requests.Session()
# resp1=sess.get(url="http://localhost/index.php?m=Home&c=User&a=verify&r=0.7421460428338859")
# resp2=sess.post(url="http://localhost/index.php?m=Home&c=User&a=do_login&t=0.9450750218212879",
#                     headers={"content_type":"application/x-www-form-urlencoded; charset=UTF-8"},
#                     data={"username":"18888888888","password":"123456","verify_code":"8888"})
# print(resp2.json())